package cn.uniquesoft.controller;

import cn.uniquesoft.manager.Client;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.uniquesoft.manager.ClientManager;
import cn.uniquesoft.service.IMenuService;
import cn.uniquesoft.vo.LogVO;
import cn.uniquesoft.vo.RoleMenuVO;
import cn.uniquesoft.vo.UserVO;

/**
 * @创建人 zyx
 * @创建时间 2017年6月20日 下午7:03:21
 * @描述 主界面
 */
@Controller
@RequestMapping(value = "/main")
public class MainController {

	@Autowired
	private IMenuService menuService;

	@RequestMapping(value = "/index")
	public String index(Model model) {
		UserVO userVO=null;
		String menuids="";
		int rid=0;
		RoleMenuVO rmitem=null;
		try {

			if(ClientManager.getInstance().getClient()!=null) {
				userVO = ClientManager.getInstance().getClient().getUser();
				rid = userVO.getRid();
				rmitem=this.menuService.getItemByRid(rid);
				menuids=rmitem.getImenuid();
			}


		} catch (Exception e) {
			e.printStackTrace();
			return "login/index";
		}
		if(userVO==null){
			return "login/index";
		}
		
		model.addAttribute("cname", userVO.getCname());
		model.addAttribute("menuList", this.menuService.getMenuByMenuIds(menuids));
		model.addAttribute("num",ClientManager.getInstance().getAllClient().size());
		return "main/index";
	}

	@RequestMapping(value = "/agencyindex")
	public String agencyindex() {
		return "agencyhtml/login/index";
	}
}
